package com.meituan.provider;

import com.meituan.model.OrderEntity;
import org.apache.ibatis.jdbc.SQL;

import java.text.SimpleDateFormat;
import java.util.Date;

public class OrderProvider {
    public String updatePay(String orderId){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
        return new SQL(){
            {
                UPDATE("`order`");
                SET("is_pay = 1");
                SET("pay_time='" + sdf.format(new Date())+"'");
                WHERE("`order_id` = #{orderId} ");
            }

        }.toString();
    }

    public String updateOver(String orderId){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
        return new SQL(){
            {
                UPDATE("`order`");
                SET("is_over = 1");
                SET("over_time='" + sdf.format(new Date())+"'");
                WHERE("`order_id` = #{orderId} ");
            }

        }.toString();
    }

    public String updateEvaluate(String orderId){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
        return new SQL(){
            {
                UPDATE("`order`");
                SET("is_evaluate = 1");
                SET("evaluate_time='" + sdf.format(new Date())+"'");
                WHERE("`order_id` = #{orderId} ");
            }

        }.toString();
    }

    public String insertProvider(OrderEntity orderEntity){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
        String current = sdf.format(new Date());
        return "insert into `order`(user_id,shop_id,receiving_name,receiving_telephone,receiving_address,remarks,shipping_fee,order_amount,create_time) values(#{userId},#{shopId},#{receivingName},#{receivingTelephone},#{receivingAddress},#{remarks},#{shippingFee},#{orderAmount},'"+current+"')";
    }

}
